package com.xunfang.servlet;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.xunfang.bean.Student;
import com.xunfang.service.StudentService;
import com.xunfang.utils.PageResult;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @Author lss
 * @CreateTime 2024/6/11
 * @Description
 */



@WebServlet("/student")
public class StudentServlet extends BaseServlet {

    private StudentService studentService = new StudentService();


    //分页
    public void pageQuery(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //接收当前页与一页查询多少条数据
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");

        //调用service方法
        PageResult<Student> pageResult = studentService.pageQuery(currentPage,pageSize);
        //结果转json
        String json = new ObjectMapper().writeValueAsString(pageResult);
        //响应回去
        resp.getWriter().print(json);
    }

}



